<?php

// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;
use Think\Model;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController
{


    var $uid;
    var $PublicModel;
    var $PublicLinkModel;

    function _initialize()
    {
        parent::_initialize();
        $this->uid = get_uid();
        $this->PublicModel = new \Home\Model\MemberPublicModel();
    }

    //系统首页
    public function index()
    {
        $User = M("usermenu");
        $arrmenu = $User->where()->select();
        $User = M("member");
        $arruser = $User->where(array('uid' => $this->uid))->select();
       //  dump($User->getLastSql());
        $User = M("usermenu_title");
        $arrtitle = $User->where()->select();
        foreach ($arrmenu as $v) {
            $v;
            //  print_r($v);
            foreach ($arrtitle as $x) {
                if ($v["menuid"] == $x["menuid"]) {
                    $x;
                    //    print_r($x);
                }
            }
        }
        // $zharr = array_merge_recursive($arrmenu, $arrtitle);
        //  print_r($arrmenu);
        //  print_r($arrtitle);
        // print_r($zharr);
        /* for ($b = 0; $b < 2; $b++){
         $ddd = $arrmenu[$b][menuid];
             if($b>0){
                 $c=$d;
             }
         $d=$User->where("menuid=".$ddd)->select();
             $a=array_merge($c,$d);
         }*/
        /* $Model= new Model();
         $sql="SELECT n.menutitleid as nid,c.menuid,c.menuname,n.nametitle FROM ot_usermenu_title as n LEFT JOIN ot_usermenu as c ON c.menuid=n.menuid";
         $menuarr=$Model->query($sql);
         print_r($menuarr);
         dump($Model->getLastSql());*/
        //var_export($_SESSION);
        //  $this->assign("a",$a);
        $this->assign("arruser", $arruser);
        $this->assign("arrmenu", $arrmenu);
        $this->assign("arrtitle", $arrtitle);
        // dump($User->getLastSql());
        $this->display();
    }


    public function  news()
    {
        $User = M("news");
        $arrnews = $User->where()->order("newstime desc")->select();
        $this->assign('arrnews', $arrnews);
        $User = M("usermenu");
        $arrmenu = $User->where()->select();
        $this->assign("arrmenu", $arrmenu);
        $data = $this->PublicModel->where(array('uid' => $this->uid))->find();
        //dump($User->getLastSql());
        $this->assign('data', $data);
        $this->assign('domain', 'http://' . $_SERVER['HTTP_HOST']);
        $this->display();
    }


    public function integral(){
        $this->display();
    }
}
